<div class="layui-fluid layui-anim febs-anim" id="febs-user" lay-title="打卡统计">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">打卡类型</label>
                                        <div class="layui-input-inline">
                                            <select name="type">
                                                <option value="">请选择打卡类型</option>
                                                <option value="1">上课</option>
                                                <option value="0">下课</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">状态</label>
                                        <div class="layui-input-inline">
                                            <select name="status">
                                                <option value=""></option>
                                                <option value="1">正常</option>
                                                <option value="0">缺卡</option>
                                                <option value="3">请假</option>
                                                <option value="4">补卡</option>
                                            </select>
                                        </div>
                                    </div>


                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">
                                    <i class="layui-icon">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">
                                    <i class="layui-icon">&#xe79b;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="user:add,user:update,user:password:reset,user:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="use_table" lay-data="{id: 'userTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="user-status">
    {{#
    var status = {
    1:{title: '正常', color: 'green'},
    0:{title: '缺卡', color: 'volcano'},
    3: {title: '请假', color: 'red'},
    4: {title: '补卡', color: 'blue'}
    }[d.status];
    }}
    <span class="layui-badge febs-tag-{{status.color}}">{{ status.title }}</span>
</script>

<script type="text/html" id="user-option">
    <span shiro:lacksPermission="user:view,user:update,user:delete">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>

    <a lay-event="edit" shiro:hasPermission="user:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i>设置</a>
    <a lay-event="del" shiro:hasPermission="user:delete"><i
            class="layui-icon febs-edit-area febs-red">&#xe7f9;删除</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#febs-user'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;

        form.render();

        initTable();

        laydate.render({
            elem: '#user-createTime',
            range: true,
            trigger: 'click'
        });

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('use_table');
                if (name === 'add') {
                    febs.modal.open('新增实验', 'system/experiment/project/add', {
                        btn: ['提交', '重置'],
                        area: $(window).width() <= 750 ? '95%' : '50%',
                        yes: function (index, layero) {
                            $('#add').find('#submit').trigger('click');
                        },
                        btn2: function () {
                            $('#add').find('#reset').trigger('click');
                            return false;
                        }
                    });
                }
                if (name === 'delete') {
                    if (!checkStatus.data.length) {
                        febs.alert.warn('请选择需要删除的课程');
                    } else {
                        febs.modal.confirm('删除课程', '确定删除该课程？', function () {
                            var userIds = [];
                            layui.each(checkStatus.data, function (key, item) {
                                userIds.push(item.projectId)
                            });
                            deleteUsers(userIds.join(','));
                        });
                    }
                }

                if (name === 'export') {
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'user/excel', params, '课程信息表.xlsx');
                }
            },
            options: [{
                name: 'add',
                title: '新增项目',
                perms: 'experimentProject:add'
            }, {
                name: 'delete',
                title: '删除课程',
                perms: 'user:delete'
            }, {
                name: 'export',
                title: '导出Excel',
                perms: 'user:export'
            }]
        });

        treeSelect.render({
            elem: $view.find('#dept'),
            type: 'get',
            data: ctx + 'dept/select/tree',
            placeholder: '请选择',
            search: false
        });

        table.on('tool(use_table)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {

                febs.modal.view('课程信息', 'system/experiment/project/view/' + data.projectId, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'del') {
                febs.modal.confirm('删除实验项目', '确定删除该实验项目？', function () {
                    deleteUsers(data.projectId);
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改课程', 'system/experiment/project/update/' + data.projectId, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#add').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
            if (layEvent === 'report') {
                window.location.href = ctx + "experimentProject/downloadFile?objectName=" + data.reportUrl;
            }


        });

        table.on('sort(use_table)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            alert("1111");
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            console.log("params-------------------" + params);
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'use_table',
                url: ctx + 'attendance/list',
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'createTime', title: '打卡时间', minWidth: 100,
                            templet: function (d) {
                                return layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss")
                            }
                        },
                        {field: 'address', title: '打卡地址'},
                        {field: 'type', title: '类型',
                            templet:function (d) {
                                if (d.type==1){
                                    return '上课';
                                }else if (d.type == 0){
                                    return '下课';
                                }else {
                                    return "";
                                }
                            }
                        },
                        {title: '状态', templet: '#user-status'}
                      /*  {title: '操作', toolbar: '#user-option', minWidth: 140}*/
                    ]
                ]
            });
        }

        function getQueryParams() {
            return {
                status: $searchForm.find("select[name='status']").val(),
                type: $searchForm.find("select[name='type']").val(),
                invalidate_ie_cache: new Date()
            };
        }

        function deleteUsers(projectIds) {

            febs.get(ctx + 'experimentProject/delete/' + projectIds, null, function () {
                febs.alert.success('删除实验项目成功');
                $query.click();
            });
        }
    })
</script>